package com.zpark.controller;

import com.zpark.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @PackageName: com.zpark.controller
 * @ClassName: ConsumerController
 * @Description:
 * @author: RZS
 * @date: 2024/4/17  9:42
 */
@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    // 获取指定服务信息
    @Autowired
    private LoadBalancerClient client;

    @GetMapping("/choose")
    public Object getChose(){
        return client.choose("ribbon-consumer");
    }

    @GetMapping("/ribbon")
    public User get(){
        return restTemplate.getForObject(
                "http://RIBBON-SERVER/server/get",
                User.class
        );
    }
}
